/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.apiGenerator.dataType.entityInterface.resourceInfo;

import com.inspur.edp.bef.spi.entity.CodeRuleInfo;
import com.inspur.edp.caf.generator.baseInfo.ParameterInfo;
import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
import com.inspur.edp.caf.generator.utils.ExpressionUtils;
import com.inspur.edp.cef.designtime.api.IGspCommonDataType;
import com.inspur.edp.cef.spi.entity.resourceInfo.builinImpls.CefModelResInfoImpl;
import java.util.ArrayList;
import org.eclipse.jdt.core.dom.Block;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.SuperConstructorInvocation;

public class ResourceInfoCtorGenerator extends ClassMethodGenerator {

    private String className;
    private IGspCommonDataType dataType;
    private String paramName = "modelInfo";
    protected ResourceInfoCtorGenerator(String className, IGspCommonDataType dataType) {
        this.className = className;
        this.dataType = dataType;
    }

    @Override
    protected final TypeInfo getReturnType() {
        return null;
    }
    @Override
    protected final String getMethodName() {
        return className;
    }
    @Override
    protected final ArrayList<Modifier.ModifierKeyword> getAccessModifiers() {
        ArrayList<Modifier.ModifierKeyword> list=new ArrayList<>();
        list.add(Modifier.ModifierKeyword.PUBLIC_KEYWORD);
        return list;
    }
    @Override
    protected ArrayList<ParameterInfo> getParameterCollection() {
        ParameterInfo param = new ParameterInfo();
        param.setParamType(new TypeInfo(CefModelResInfoImpl.class));
        param.setParamName(paramName);
        ArrayList<ParameterInfo> list = new ArrayList<>();
        list.add(param);
        return list;
    }

    @Override
    protected final boolean buildIsConstructor() {
        return true;
    }

    @Override
    protected  Block buildMethodBody() {
        Block block=ast.newBlock();
        addImport(CodeRuleInfo.class.getTypeName());
        SuperConstructorInvocation superConstructorInvocation=	ast.newSuperConstructorInvocation();
        superConstructorInvocation.arguments().add(ExpressionUtils.getStringLiteral(ast, dataType.getCode()));
        superConstructorInvocation.arguments().add(ExpressionUtils.getStringLiteral(ast, dataType.getI18nResourceInfoPrefix().concat(".").concat("Name")));
        superConstructorInvocation.arguments().add(ast.newSimpleName(paramName));
        superConstructorInvocation.arguments().add(ExpressionUtils.getStringLiteral(ast, dataType.getID()));
        block.statements().add(superConstructorInvocation);
        addExtendStatements(block);
        return block;
    }

    protected void addExtendStatements(Block block){

    }
}
